
var runStates = {'EXECUTE':'执行中', 
                'SUSPEND':'已暂停', 
                'STARTING':'启动中',
                'STOPING':'正在终止',

                'STOP_HAND':'手动终止', 
                'STOP_PROFIT':'已止盈', 
                'STOP_LOSS':'已止损',
                'STOP_TIME':'已定时终止',
                'STOP_AUTO':'已自动终止',
                'FORCE_CLOSE':'已强平',
                'STOP_OPERATOR':'操作员终止'};
export default {

  /** 获取运行状态
  * 
  * @param {Boolean} isStop turn 已终止 
  * @param {Boolean} isFollow turn 跟单策略
  * @param {String} state 运行状态 
  */
  getRunState(isStop, isFollow, state) {

    if (isStop) {
      return isFollow ? '跟单终止' : runStates[state];
    } else {
      var bol = (isFollow && (state == 'EXECUTE' || state == 'SUSPEND'));
      return bol ? '跟单中' : runStates[state];
    }
  },

  /** 获取运行时长
  * 
  * @param {String} startTime 开始时间
  * @param {String} endTime  结束时间
  * @param {String} D 天单位
  * @param {String} H 时单位
  * @param {String} M 分单位
  */
  getRunTime(startTime, endTime, D='', H='', M=''){

    endTime = (endTime == '' || endTime == undefined) ? new Date().getTime() : endTime;
    var disTime = endTime - startTime;
    var day = Math.floor(disTime / 86400000);
    var hour = Math.floor(disTime % 86400000 / 3600000);
    var min = Math.floor(disTime % 86400000 % 3600000 / 60000);
    return day + D + hour + H + min + M;
  },

  //时间转换(年/月/日 时:分)
  getParseTime(timestamp){

    timestamp = timestamp ? Number(timestamp) : new Date().getTime();
    var time = new Date(timestamp);
    var year = time.getFullYear()
    var month = time.getMonth()+1

    month = month < 10 ? "0"+month : month;

    var day = time.getDate();
    day = day < 10 ? "0"+day : day;

    var hour = time.getHours();
    hour = hour < 10 ? "0"+hour : hour;

    var minute = time.getMinutes();
    minute = minute < 10 ? "0"+minute : minute;

    return year+"/"+month+"/"+day + ' ' + hour +":"+ minute;
  },
}